#ifndef USERMANAGER_H
#define USERMANAGER_H

#include <QObject>
#include <QString>
#include "jsonconfigwriter.h"

class QLineEdit;
class QComboBox;
class QPushButton;
class QListWidget;

class UserManager : public QObject
{
    Q_OBJECT
public:
    explicit UserManager(QLineEdit *input,
                         QComboBox *combo,
                         QPushButton *addBtn,
                         QPushButton *delBtn,
                         QListWidget *listWidgetHide,
                         QObject *parent = nullptr);

    // ⭐ 允许在切换 UI 文件时更新 JsonConfigWriter
    void setWriter(JsonConfigWriter *writer);

    // ⭐ 获取当前用户输入（输入框 or 下拉框）
    QString getCurrentUserInput() const;

    // ⭐ 检查指定用户是否在 ui.json 内
    bool checkUserInUiJson(const QString &username, bool expectExists) const;
    void updateUiPath(const QString &uipath);


signals:
    // 用户新增/删除/切换信号
    void userAdded(const QString &user);
    void userDeleted(const QString &user);
    void switchToUser(const QString &user);

private slots:
    // 槽函数：点击新增/删除按钮
    void onAddUser();
    void onDeleteUser();

private:
    QLineEdit *m_input;
    QComboBox *m_comboBox;
    QPushButton *m_addButton;
    QPushButton *m_deleteButton;
    QListWidget *m_listWidgetHide;
    QString m_uiPath;

    JsonConfigWriter *m_jsonconfigwriter;
    QStringList currentHideControlsFromUI() const;
};

#endif // USERMANAGER_H
